var e = null, t = null, i = null, a = null, n = null, r = null, s = null, o = null, helper=null;

"undefined" != typeof wx && (e = require("./hj.js"), t = require("./utils/page.js"), helper = require("./utils/helper.js"),
i = require("./utils/request.js"), a = require("./api.js"), n = require("./utils/utils.js"), 
r = require("./commons/order-pay/order-pay.js"), s = require("./utils/uploader"), 
o = require("./utils/login.js"));
var u = App({
    is_on_launch: !0,
    onShowData: null,
    _version: "2.8.4",
    query: null,
    helper: helper,
    onLaunch: function(e) {
        this.setApi(), a = this.api, this.getNavigationBarColor(), this.getStoreData(), 
        this.getCatList();
    },
    globalData: {
      tab_cat_id: 0,
      nav_index:0
    },
    onShow: function(e) {　
        //wx.hideTabBar()
        e.scene && (this.onShowData = e), e && e.query && (this.query = e.query);
        this.getNewApp();
    },
    getNewApp: function () {
        //创建 UpdateManager 实例
        const updateManager = wx.getUpdateManager();
        //检测版本更新
        updateManager.onCheckForUpdate(function (res) {
        // 请求完新版本信息的回调
        if (res.hasUpdate) {
            //监听小程序有版本更新事件
            updateManager.onUpdateReady(function () {
            wx.showModal({
                title: '更新提示',
                content: '新版本已经准备好，是否重启应用？',
                success(res) {
                if (res.confirm) {
                    // 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
                    updateManager.applyUpdate();
                }
                }
            })
            })
            updateManager.onUpdateFailed(function () {
            // 新版本下载失败
            wx.showModal({
                title: '已经有新版本咯~',
                content: '请您删除当前小程序，到微信 “发现-小程序” 页，重新搜索打开呦~',
            })
            })
        }
        })
    },
    getStoreData: function() {
        var e = this;
        this.request({
            url: a.default.store,
            success: function(t) {
                0 == t.code && (e.hj.setStorageSync("store", t.data.store), e.hj.setStorageSync("store_name", t.data.store_name), 
                e.hj.setStorageSync("show_customer_service", t.data.show_customer_service), e.hj.setStorageSync("contact_tel", t.data.contact_tel), 
                e.hj.setStorageSync("share_setting", t.data.share_setting), e.permission_list = t.data.permission_list, 
                e.hj.setStorageSync("wxapp_img", t.data.wxapp_img), e.hj.setStorageSync("wx_bar_title", t.data.wx_bar_title));
            },
            complete: function() {}
        });
    },
    getCatList: function() {
        var e = this;
        this.request({
            url: a.default.cat_list,
            success: function(t) {
                if (0 == t.code) {
                    var i = t.data.list || [];
                    e.hj.setStorageSync("cat_list", i);
                }
            }
        });
    },
    saveFormId: function(e) {
        this.request({
            url: a.user.save_form_id,
            data: {
                form_id: e
            }
        });
    },
    loginBindParent: function(e) {
        var t = this;
        if ("" == t.hj.getStorageSync("access_token")) return !0;
        t.bindParent(e);
    },
    bindParent: function(e) {
        var t = this;
        if ("undefined" != e.parent_id && 0 != e.parent_id) {
            var i = t.hj.getStorageSync("user_info");
            t.hj.getStorageSync("share_setting").level > 0 && 0 != e.parent_id && t.request({
                url: a.share.bind_parent,
                data: {
                    parent_id: e.parent_id
                },
                success: function(e) {
                    0 == e.code && (i.parent = e.data, t.hj.setStorageSync("user_info", i));
                }
            });
        }
    },
    shareSendCoupon: function(e) {
        var t = this;
        t.hj.showLoading({
            mask: !0
        }), e.hideGetCoupon || (e.hideGetCoupon = function(i) {
            var a = i.currentTarget.dataset.url || !1;
            e.setData({
                get_coupon_list: null
            }), a && t.hj.navigateTo({
                url: a
            });
        }), this.request({
            url: a.coupon.share_send,
            success: function(t) {
                0 == t.code && e.setData({
                    get_coupon_list: t.data.list
                });
            },
            complete: function() {
                t.hj.hideLoading();
            }
        });
    },
    getauth: function(e) {
        var t = this;
        t.hj.showModal({
            title: "是否打开设置页面重新授权",
            content: e.content,
            confirmText: "去设置",
            success: function(i) {
                i.confirm ? t.hj.openSetting({
                    success: function(t) {
                        e.success && e.success(t);
                    },
                    fail: function(t) {
                        e.fail && e.fail(t);
                    },
                    complete: function(t) {
                        e.complete && e.complete(t);
                    }
                }) : e.cancel && t.getauth(e);
            }
        });
    },
    setApi: function() {
        function e(i) {
            for (var a in i) "string" == typeof i[a] ? i[a] = i[a].replace("{$_api_root}", t) : i[a] = e(i[a]);
            return i;
        }
        var t = this.siteInfo.siteroot;
        t = t.replace("app/index.php", ""), t += "addons/zjhj_mall/core/web/index.php?store_id=-1&r=api/", 
        this.api = e(this.api);
        var i = this.api.default.index, a = i.substr(0, i.indexOf("/index.php"));
        this.webRoot = a;
    },
    webRoot: null,
    siteInfo: require("./siteinfo.js"),
    currentPage: null,
    pageOnLoad: function(e, t) {
        this.page.onLoad(e, t);
    },
    pageOnReady: function(e) {
        this.page.onReady(e);
    },
    pageOnShow: function(e) {
        //wx.hideTabBar()
        this.page.onShow(e);
    },
    pageOnHide: function(e) {
        this.page.onHide(e);
    },
    pageOnUnload: function(e) {
        this.page.onUnload(e);
    },
    getNavigationBarColor: function() {
        var e = this;
        e.request({
            url: a.default.navigation_bar_color,
            success: function(t) {
                0 == t.code && (e.hj.setStorageSync("_navigation_bar_color", t.data), e.setNavigationBarColor());
            }
        });
    },
    setNavigationBarColor: function() {
        var e = this.hj.getStorageSync("_navigation_bar_color");
        e = e ? e : '#ffffff'
        e && this.hj.setNavigationBarColor(e);
    },
    loginNoRefreshPage: [ "pages/index/index", "mch/shop/shop" ],
    navigatorClick: function(e, t) {
        var i = e.currentTarget.dataset.open_type;
        if ("redirect" == i) return !0;
        if ("wxapp" == i) {
            var a = e.currentTarget.dataset.path;
            "/" != a.substr(0, 1) && (a = "/" + a), this.hj.navigateToMiniProgram({
                appId: e.currentTarget.dataset.appid,
                path: a,
                complete: function(e) {}
            });
        }
        if ("tel" == i) {
            var n = e.currentTarget.dataset.tel;
            this.hj.makePhoneCall({
                phoneNumber: n
            });
        }
        return !1;
    },
    hj: e,
    page: t,
    request: i,
    api: a,
    utils: n,
    order_pay: r,
    uploader: s,
    login: o,
    setRequire: function() {
        this.hj = require("./hj.js"), this.request = require("./utils/request.js"), this.page = require("./utils/page.js"), 
        this.api = require("./api.js"), this.utils = require("./utils/utils.js"), this.order_pay = require("./commons/order-pay/order-pay.js"), 
        this.uploader = require("./utils/uploader"), this.login = require("./utils/login.js");
    },
    getPlatform: function() {
        return "undefined" != typeof my ? "my" : "undefined" != typeof wx ? "wx" : null;
    },
    getTopPage: function () {
        let page = getCurrentPages();
        return page[page.length - 1]; 
    }
});

"undefined" != typeof my && (u.setRequire(), u.setApi());